package com.gilight.base.controller;

import com.gilight.base.aspect.annotation.OperatorLog;
import com.gilight.base.base.ResultEntity;
import com.gilight.base.service.SysUserZzjgService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/web/trUserZzjg")
public class SysUserZzjgController {

    @Resource
    private SysUserZzjgService sysUserZzjgService;

    @ApiOperation(value = "根据条件查询组织机构的所有用户")
    @RequestMapping(value = "/admin/getUserZzjgList", method = RequestMethod.GET,name="根据条件查询组织机构的所有用户")
    @OperatorLog(value = "根据条件查询组织机构的所有用户",operateType= "查询")
    public ResultEntity getUserZzjgList(@RequestParam int startPage, @RequestParam int pageSize,@RequestParam String searchName) {
        ResultEntity resultEntity = new ResultEntity();
        Map<String, Object> map = new HashMap<>();
        PageHelper.startPage(startPage,pageSize);
        map.put("searchName", searchName);
        List<Map<String, Object>> userList = sysUserZzjgService.getUserZzjgList(map);
        PageInfo pageInfo = new PageInfo(userList);
        resultEntity.setData(pageInfo);
        return resultEntity;
    }
    @ApiOperation(value = "根据组织机构查询用户")
    @RequestMapping(value = "/admin/getUserByZzjg", method = RequestMethod.GET,name="根据组织机构查询用户")
    @OperatorLog(value = "根据组织机构查询用户",operateType= "查询")
    public ResultEntity getUserByZzjg(@RequestParam int startPage, @RequestParam int pageSize,@RequestParam String zzjgId) {
        ResultEntity resultEntity = new ResultEntity();
        Map<String, Object> map = new HashMap<String, Object>();
        PageHelper.startPage(startPage,pageSize);
        map.put("zzjgId", zzjgId);
        List<Map<String, Object>> deptList = sysUserZzjgService.getUserByZzjg(map);
        PageInfo pageInfo = new PageInfo(deptList);
        resultEntity.setData(pageInfo);
        return resultEntity;
    }

    @ApiOperation(value = "是否部门负责人")
    @RequestMapping(value = "/admin/isManager", method = RequestMethod.GET,name="是否部门负责人")
    @OperatorLog(value = "是否部门负责人",operateType= "查询")
    public ResultEntity isManager(@RequestParam String zzjgId) {
        ResultEntity resultEntity = new ResultEntity();
        boolean isManager= sysUserZzjgService.isManager(zzjgId);
        resultEntity.setData(isManager);
        return resultEntity;
    }
    @ApiOperation(value = "设置部门负责人")
    @RequestMapping(value = "/admin/addManager", method = RequestMethod.GET,name="设置部门负责人")
    @OperatorLog(value = "设置部门负责人",operateType= "修改")
    public ResultEntity addManager(@RequestParam String zzjgId,@RequestParam String id) {
        ResultEntity resultEntity = new ResultEntity();
        sysUserZzjgService.addManager(zzjgId,id);
        return resultEntity;
    }

    @ApiOperation(value = "获取当前用户所在的组织机构")
    @RequestMapping(value = "/web/getCurrentUserZzjgs", method = RequestMethod.GET,name="获取当前用户所在的组织机构")
    @OperatorLog(value = "获取当前用户所在的组织机构",operateType= "查询")
    public ResultEntity getCurrentUserZzjgs() {
        ResultEntity resultEntity = new ResultEntity();
        List<Map<String,Object>> zzjgs=sysUserZzjgService.getCurrentUserZzjgs();
        resultEntity.setData(zzjgs);
        return resultEntity;
    }

}
